package com.pentofab.payrollmanagement.ui.controller;

import java.net.URL;
import java.util.ResourceBundle;

import com.pentofab.payrollmanagement.application.PayRollApplication;
import com.pentofab.payrollmanagement.application.PayrollApplicationFactory;
import com.pentofab.payrollmanagement.dao.model.Company;
import com.pentofab.payrollmanagement.dao.model.UserAccounts;

import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;

public class SalaryTabController extends AbstractUIController implements
		FormValidator {
	
	private Company company;
	private UserAccounts userAccounts;
	@FXML
    private VBox root;  
    @FXML
    private ListView<String> salaryListView;  
	
	@Override
	public boolean isValid() {
		return false;
	}

	@Override
	public String getValidationMessage() {
		return null;
	}

	@Override
	public Parent getView() {
		return root;
	}

	@Override
	public String getTitle() {
		return "Salary Module";
	}

	@Override
	public void refreshUI(Object... args) {
		
		if (args != null && args.length > 0) {
			Company company = (Company) args[0];
			this.company = company;
			
			if(args.length > 1 && args[1] instanceof UserAccounts){
				userAccounts = (UserAccounts) args[1];
			}
		}

	}
	
	public void goBack() {

		PayrollApplicationFactory.getMainController().showScreen(
				MainController.COMPANIES_LIST_SCREEN, false, userAccounts);
	}
	
	public void open() {
		if(salaryListView.getSelectionModel().getSelectedIndex() == 0)
			PayrollApplicationFactory.getMainController().showScreen(MainController.SalaryDisplayAttendance, true, company,userAccounts);
		/*if(salaryListView.getSelectionModel().getSelectedIndex() == 1)
			PayrollApplicationFactory.getMainController().showScreen(MainController.viewSalaryProfile, true, company,userAccounts);*/
		if(salaryListView.getSelectionModel().getSelectedIndex() == 1)
			PayrollApplicationFactory.getMainController().showScreen(MainController.SalaryAdvance, true, company,userAccounts);
		if(salaryListView.getSelectionModel().getSelectedIndex() == 2)
			PayrollApplicationFactory.getMainController().showScreen(MainController.SalaryStracture, true, company,userAccounts);
		if(salaryListView.getSelectionModel().getSelectedIndex() == 3)
			PayrollApplicationFactory.getMainController().showScreen(MainController.DisplaySalaryStracture, true, company,userAccounts);
		if(salaryListView.getSelectionModel().getSelectedIndex() == 4)
			PayrollApplicationFactory.getMainController().showScreen(MainController.SalaryReport, true, company,userAccounts);
		if(salaryListView.getSelectionModel().getSelectedIndex() == 5)
			PayrollApplicationFactory.getMainController().showScreen(MainController.BankInfo, true, company,userAccounts);
	}
	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		
		salaryListView.getItems().add("Attendance Details");
		salaryListView.getItems().add("Salary Advance");
		salaryListView.getItems().add("Salary Stracture");
		salaryListView.getItems().add("View Salary Stracture for All Employee");
		salaryListView.getItems().add("Salary Report");
		salaryListView.getItems().add("Bank Information");
	}

}
